﻿using IService.Utility;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IService.Model;
using IService.Utility;

namespace IService.User_center
{
    public partial class UserInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.BindData();
            }
        }

        public void BindData()
        {
            User curentUser = SessionState.CurrentUser;

            //显示联系方式
            lblRealUserName.Text = curentUser.RealUserName;
            lblPhone.Text = curentUser.Phone;
            lblUserMobile.Text = curentUser.UserMobile;
            lblUserFax.Text = curentUser.UserFax;
            lblEmail.Text = curentUser.Email;
            lblUserAddress.Text = curentUser.UserAddress;
            lblCompanyName.Text = curentUser.CompanyName;
            lblCompanyName2.Text = curentUser.CompanyName;

            if (string.IsNullOrEmpty(curentUser.UserRole))
            {
                //用户角色为空,不显示用户基本信息
                this.divUserInfo.Style.Add("display", "none");
            }
            else
            {
                //用户角色不为空,显示用户基本信息
                this.divUserInfoModify.Style.Add("display", "none");
                lblUserName.Text = curentUser.UserName;
                lblRegistDateTime.Text = curentUser.RegistDateTime.ToString("yyyy-MM-dd");
                lblLoginDate.Text = DateTime.Now.ToString("yyyy-MM-dd");

                //邦定用户角色
                string[] chkSelect = curentUser.UserRole.Split(',');
                foreach (string select in chkSelect)
                {
                    for (int i = 0; i < this.cblUserRole.Items.Count; i++)
                    {
                        if (string.Compare(this.cblUserRole.Items[i].Value, select, true) == 0)
                        {
                            this.cblUserRole.Items[i].Selected = true;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(curentUser.CompanyProfile))
            {
                //公司简介为空,不显示公司信息
                this.divCompayInfo.Style.Add("display", "none");
            }
            else
            {
                //公司简介不为空,显示公司信息
                this.divCompayInfoModify.Style.Add("display", "none");
                lblEmployeesTotal.Text = curentUser.EmployeesTotal.ToString();
                lblFoundedDate.Text = curentUser.FoundedDate.ToString("yyyy-MM-dd");
                lblCompanyPhone.Text = curentUser.CompanyPhone;
                lblCompanyAddress.Text = curentUser.CompanyAddress;

                //邦定行业分类
                string[] chkSelect = curentUser.IndustryClassification.Split(',');
                foreach (string select in chkSelect)
                {
                    for (int i = 0; i < this.cblIndustryClassification.Items.Count; i++)
                    {
                        if (string.Compare(this.cblIndustryClassification.Items[i].Value, select, true) == 0)
                        {
                            this.cblIndustryClassification.Items[i].Selected = true;
                        }
                    }
                }

                txtSupply.Text = curentUser.Supply;
                txtPurchase.Text = curentUser.Purchase;
                txtCompanyProfile.Text = curentUser.CompanyProfile;
            }
        }
    }
}